
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Comparator;

public class Code1985 {

    public static void main(String[] args) {
        Code1985 code1985 = new Code1985();
        String s = code1985.kthLargestNumber2(new String[]{"683339452288515879","7846081062003424420","4805719838","4840666580043","83598933472122816064","522940572025909479","615832818268861533","65439878015","499305616484085","97704358112880133","23861207501102","919346676","60618091901581","5914766072","426842450882100996","914353682223943129","97","241413975523149135","8594929955620533","55257775478129","528","5110809","7930848872563942788","758","4","38272299275037314530","9567700","28449892665","2846386557790827231","53222591365177739","703029","3280920242869904137","87236929298425799136","3103886291279"},
        3);
        System.out.println(s);
    }
    public String kthLargestNumber(String[] nums, int k) {
        String t = "";
        BigDecimal[] a = new BigDecimal[nums.length];
        for (int i = 0; i < nums.length; i++) {
            BigDecimal bigDecimal = new BigDecimal(nums[i]);
            a[i] = bigDecimal;
        }
        Arrays.sort(a);

        return a[a.length-k].toString();
    }


    public String kthLargestNumber2(String[] nums, int k) {
       Arrays.sort(nums, new Comparator<String>() {
           public int compare(String o1, String o2) {
               if (o1.length()> o2.length()) return  1;
               if (o1.length()< o2.length()) return -1;
               if (o1.length() == o2.length()){
                   char[] chars = o1.toCharArray();
                   char[] chars1 = o2.toCharArray();
                   for (int i = 0; i < chars.length; i++) {
                        if (chars[i] < chars1[i]) return -1;
                       else if (chars[i]> chars1[i]) return 1;
                       if (i == chars.length){
                           return  0;
                       }
                   }
               }
               return 0;
           }
       });
        System.out.println(Arrays.toString(nums));
        return nums[nums.length-k].toString();
    }

}
